#!/user/bin/env node

const http = require('http'),
      url = require('url'),
      qs = require('querystring'),
      log = console.log;

http.createServer((req,res)=>{
  log(req.url);
  let addr = url.parse(req.url);
  log('addr:',addr);
  if(addr.pathname === '/add'){
    const arg = qs.parse(addr.query);
    const r = {};
    r.add = Number(arg.x) + Number(arg.y);
    res.end(JSON.stringify(r));
  }
}).listen(8080); 
